package com.sysu.homework.service.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.sysu.homework.DAO.HomeworkResultDAO;
import com.sysu.homework.DAO.StudentDAO;
import com.sysu.homework.model.HomeworkResult;
import com.sysu.homework.service.HomeworkResultService;
import com.sysu.homework.service.StudentService;

@Component("homeworkResultService")
public class HomeworkResultServiceImpl implements HomeworkResultService {
	private HomeworkResultDAO homeworkResultDAO;
	private StudentDAO studentDAO;

	@Override
	public int saveOrUpdate(HomeworkResult homeworkResult) {
		if (homeworkResult != null)
			return homeworkResultDAO.saveOrUpdate(homeworkResult);
		return -1;
	}

	@Resource
	public void setHomeworkResultDAO(HomeworkResultDAO homeworkResultDAO) {
		this.homeworkResultDAO = homeworkResultDAO;
	}

	public HomeworkResultDAO getHomeworkResultDAO() {
		return homeworkResultDAO;
	}

	@Override
	public HomeworkResult getHomeworkResultByFilename(String filename) {
		return homeworkResultDAO.getHomeworkResultByFilename(filename);
	}

	@Override
	public List<HomeworkResult> getMyHomeworkResults(int studentid) {

		return homeworkResultDAO.getHomeworkResultsByStudentId(studentid);
	}

	@Override
	public List<HomeworkResult> getMyGroupHomeworkResults(int studentid) {
		int groupid = studentDAO.getGroupId(studentid);
		return homeworkResultDAO.getHomeworkResultsByGroupId(groupid);
	}

	@Override
	public List<HomeworkResult> getAllHomeworkResults() {
		return homeworkResultDAO.getHomeworkResults();
	}
	
	public StudentDAO getStudentDAO() {
		return studentDAO;
	}

	@Resource
	public void setStudentDAO(StudentDAO studentDAO) {
		this.studentDAO = studentDAO;
	}

	@Override
	public boolean isExistsResult(int homeworkid, int studentid) {
		return homeworkResultDAO.isExistsResult(homeworkid,studentid);
	}


}
